Skip to content

Conversation

@ericallam
Copy link
Member

@ericallam ericallam commented May 16, 2025

Summary by CodeRabbit

  • New Features
    • Added support for parsing and replicating payloads encoded with superjson, enabling correct handling of complex data types such as BigInt, Date, and Map.
  • Tests
    • Introduced a new integration test to verify replication and deserialization of superjson-encoded payloads, ensuring data integrity for complex types.

@changeset-bot
Copy link

changeset-bot bot commented May 16, 2025

⚠️ No Changeset found

Latest commit: 4a4b359

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 2025

Walkthrough

A new asynchronous function, parsePacketAsJson, was introduced to handle packet deserialization with special treatment for superjson payloads, ensuring conversion to plain JSON. The web application's replication service was updated to use this new function. Additionally, an integration test was added to validate replication of superjson-encoded payloads.

Changes

File(s) Change Summary
packages/core/src/v3/utils/ioSerialization.ts Added parsePacketAsJson function to parse packets, converting superjson payloads to plain JSON.
apps/webapp/app/services/runsReplicationService.server.ts Updated import and usage from parsePacket to parsePacketAsJson in the replication service.
apps/webapp/test/runsReplicationService.test.ts Added an integration test to verify replication and correct deserialization of superjson-encoded TaskRun payloads.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Integration Test
    participant ReplicationService as RunsReplicationService
    participant IO as ioSerialization (parsePacketAsJson)
    participant ClickHouse as ClickHouse DB

    Test->>ReplicationService: Insert TaskRun with superjson payload
    ReplicationService->>IO: parsePacketAsJson(packet)
    IO-->>ReplicationService: Return plain JSON from superjson
    ReplicationService->>ClickHouse: Replicate TaskRun record
    Test->>ClickHouse: Query for replicated TaskRun and payload
    ClickHouse-->>Test: Return record and deserialized payload
Loading

Poem

In the warren where packets run,
Superjson now meets the sun.
With new parsing, plain and clear,
Complex types have less to fear.
Tests now hop and payloads sing,
JSON joy in every spring! 🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 2 workspace projects
 WARN  Ignoring not compatible lockfile at /tmp/eslint/pnpm-lock.yaml
 ERR_PNPM_FETCH_404  GET http://10.0.0.28:4873/tsx: Not Found - 404

This error happened while installing a direct dependency of /tmp/eslint

tsx is not in the npm registry, or you have no permission to fetch it.

No authorization header was set for the request.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/src/v3/utils/ioSerialization.ts (1)

44-72: Good implementation for handling superjson payloads properly

The new parsePacketAsJson function effectively addresses the issue with BigInt and other complex data types by parsing the superjson data and then immediately serializing it back to plain JSON. This ensures that complex types like BigInt, which ClickHouse doesn't support, are properly converted to string representations.

Consider wrapping switch case declarations in blocks to prevent scope leakage:

    case "application/super+json":
-      const { parse, serialize } = await loadSuperJSON();
-
-      const superJsonResult = parse(value.data);
-
-      const { json } = serialize(superJsonResult);
+      {
+        const { parse, serialize } = await loadSuperJSON();
+
+        const superJsonResult = parse(value.data);
+
+        const { json } = serialize(superJsonResult);
+
+        return json;
+      }
-      return json;
🧰 Tools
🪛 Biome (1.9.4)

[error] 56-56: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 58-58: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 60-60: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between bb7173b and 4a4b359.

📒 Files selected for processing (3)
  • apps/webapp/app/services/runsReplicationService.server.ts (2 hunks)
  • apps/webapp/test/runsReplicationService.test.ts (2 hunks)
  • packages/core/src/v3/utils/ioSerialization.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/webapp/app/services/runsReplicationService.server.ts (2)
packages/core/src/v3/tryCatch.ts (1)
  • tryCatch (8-15)
packages/core/src/v3/utils/ioSerialization.ts (1)
  • parsePacketAsJson (44-72)
packages/core/src/v3/utils/ioSerialization.ts (1)
packages/core/src/v3/index.ts (1)
  • IOPacket (66-66)
🪛 Biome (1.9.4)
packages/core/src/v3/utils/ioSerialization.ts

[error] 56-56: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 58-58: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 60-60: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
apps/webapp/app/services/runsReplicationService.server.ts (1)

639-639: Updated to use the new parsePacketAsJson function

This change correctly implements the fix for BigInt and other complex types by using the newly created parsePacketAsJson instead of the previous parsePacket. This ensures that complex types in superjson payloads will be properly transformed into plain JSON before being sent to ClickHouse.

apps/webapp/test/runsReplicationService.test.ts (2)

9-9: Added superjson dependency for testing

Correctly imported the superjson library which is needed for the new test.


137-275: Great comprehensive test for superjson payload replication

This test thoroughly validates the fix by:

  1. Creating a TaskRun with complex data types (BigInt, Date, Map) in the payload
  2. Serializing it with superjson and setting the appropriate payloadType
  3. Verifying the data is correctly replicated in ClickHouse with the complex types properly converted to their JSON-compatible representations

The test ensures that:

  • BigInt values are converted to strings (e.g., "1234")
  • Date objects are converted to ISO strings
  • Maps are converted to arrays of key-value pairs

This provides excellent coverage for the fix implemented in the PR.

@ericallam ericallam merged commit ad4daa3 into main May 16, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants